package tk.mybatis.springboot;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import tk.mybatis.springboot.listener.ContextListener;


@Controller
@EnableWebMvc
@SpringBootApplication
@MapperScan(basePackages = "tk.mybatis.springboot.mapper")
public class Application extends WebMvcConfigurerAdapter {
    static Logger logger = LogManager.getLogger(Application.class);
    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(Application.class);
        springApplication.addListeners(new ContextListener());
        springApplication.run(args);
        logger.info("middle start,env=" + args[0]);
    }
    
    @RequestMapping(value = "/home")
    @ResponseBody
    public void accessVisitedit(HttpServletRequest request, HttpServletResponse response, MultipartFile file)throws Exception {
    	 File file1 = new File("C:\\测试\\ceshi.txt");  
         FileInputStream fin = new FileInputStream(file1);   
    	Path path = Paths.get("src/main/resources/upload-dir/", System.currentTimeMillis()+"111.txt");
    	Files.copy(fin, path);
    }
} 
